#include "log.h"
#include "ui_log.h"

#include <QTimer>

Log::Log(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::Log)
{
    ui->setupUi(this);


    ui->comboBox->addItems({"教学管理员","辅导员","教师","学生"});
}

Log::~Log()
{
    delete ui;
}

void Log::showLog(QString info)
{
    ui->log->setText(info);
    QTimer::singleShot(3000,[=](){ui->log->clear();});
}


void Log::on_pushButton_clicked()
{
    DB_userInfo info;
    info.account = ui->lineEdit->text().toInt();
    info.pwd = ui->lineEdit_2->text();
    info.userType = ui->comboBox->currentIndex();

    if(DB->log(info)){
        GDATA->isLogSuccess = true;
        emit GDATA->signalObj.sigLoginStatusChanged();
        qDebug()<<__FUNCTION__ <<"logOK";
    }else{
        qDebug()<<__FUNCTION__ << DB->errString;
        showLog(DB->errString);
    }

    GDATA->isLogSuccess = false;
}

